// pages/menu/menu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    isChecked:0,
    arr:[],
    name:[],
    list:[
            {
              "image":"/images/大豆及制品.png",
              "name":"豆类及制品",
              color:"white",
              "id":"01"
            },
            {
              "image":"/images/调味品.png",
              "name":"调味品",
      color:"white",
      "id":"02"
            },
            {
              "image":"/images/坚果类.png",
              "name":"坚果类",
      "id":"03"
              
            },
            {
              "image":"/images/零食及冷饮.png",
              "name":"零食及冷饮",
      "id":"04"
            },
            {
              "image":"/images/肉类.png",
              "name":"肉蛋类",
      "id":"05"
            },
            {
              "image":"/images/奶类.png",
              "name":"奶类",
      "id":"06"
            },
            {
              "image":"/images/蔬菜菌藻类.png",
              "name":"蔬菜菌藻类",
      "id":"07"
            },
            {
              "image":"/images/水果类.png",
              "name":"水果类",
      "id":"08"
            },
            {
              "image":"/images/饮料类.png",
              "name":"饮料类",
      "id":"09"
            },
            {
              "image":"/images/主食类.png",
              "name":"主食类",
      "id":"10"
            },
            {
              "image":"/images/油脂类.png",
              "name":"油脂类",
      "id":"11"
            },
            {
                "image":"/images/其他.png",
                "name":"其他",
        "id":"12"
            }
          ]    
  },
  choose(){
    this.setData({
      isChecked:true
    })
  },
    
  handleClick(e){
    let list=this.data.list;
    let arr=this.data.arr;
    let name=this.data.name
    this.setData({
      isChecked:this.data.isChecked+1
    })
    // arr.push(this.data.isChecked)
    // console.log(arr);
    this.setData({
      arr:arr
    })
    for(var item in list){
      let index='list['+item+'].color';
      if(e.currentTarget.id==list[item].name&&this.data.isChecked<=3){
        console.log(list[item].name);
        // console.log(list[item].id);
        arr.push(list[item].id);
        name.push(list[item].name);
        this.setData({
          [index]:"lightblue",
          arr:arr,
          name:name
        })
        console.log(this.data.arr)
      }
      if(this.data.isChecked>3){
        wx.showToast({
          title:'最多可以选三种',
          icon:"'none",
          duration:2000
        })
      }
   
    }
  },
  chongzhi(){
    // console.log(1);
    let list=this.data.list;
    this.setData({
      arr:[]
    })
    for(var item in list){
      let index='list['+item+'].color';
      this.setData({
        isChecked:0,
        [index]:"white"
        
      })
    }
  },
  nav(){
    let list=this.data.arr;
    let name=this.data.name;
    let one=list[0];
    let two=list[1];
    let three=list[2];

    let nameone=name[0];
    let nametwo=name[1];
    let namethree=name[2];
    // console.log(two);
    wx.navigateTo({
      url: '/pages/assort/assort?one='+one+'&two='+two+'&three='+three
      +'&nameone='+nameone+'&nametwo='+nametwo+'&namethree='+namethree
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // wx.request({
    //   method:'post',
    //   url: `http://127.0.0.1:8080/recipes/menu?one=5&tow=8&three=12`,
    //   success:res=>{
    //     console.log(res.data);
    //   }
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})